package com.logic.saas.util;

import java.sql.Timestamp;
import java.util.Date;
import java.util.Set;

import com.logic.saas.pojo.BasePojo;


public class PojoUtil {
	public static void setCommonInfo(Integer userId, BasePojo...basePojos){
		
		if (null != basePojos && 0 != basePojos.length) {
			Timestamp now = new Timestamp(new Date().getTime());
			for (BasePojo pojo : basePojos) {
				if(pojo.getId() == null){ //New PoJo
					pojo.setCreatedDate(now);
					pojo.setCreatedBy(userId==null ? 0 : userId);
					pojo.setLatestModifiedDate(now);
					pojo.setLatestModifiedBy(userId==null ? 0 : userId);
				}else{ //Update PoJo
					pojo.setLatestModifiedDate(now);
					pojo.setLatestModifiedBy(userId==null ? 0 : userId);						   					
				}
			}
		}
	}
	
	public static void setCommonInfo(Integer userId, Set<BasePojo> basePojos){
		if (null != basePojos && basePojos.size() > 0) {
			setCommonInfo(userId, (BasePojo[]) basePojos.toArray());
		}
	}
}
